<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="__EXTEND__/favicon.ico" >
    <link rel="Shortcut Icon" href="__EXTEND__/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="__EXTEND__/lib/html5shiv.js"></script>
    <script type="text/javascript" src="__EXTEND__/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="__EXTEND__/static/h-ui.admin/css/style.css" />
    <link href="__EXTEND__/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="__EXTEND__/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->

    <style>
        .clearfix:after{content:"\20";display:block;height:0;clear:both;visibility:hidden}.clearfix{zoom:1}
        .tabBar {border-bottom: 2px solid #222}
        .tabBar span {background-color: #e8e8e8;cursor: pointer;display: inline-block;float: left;font-weight: bold;height: 30px;line-height: 30px;padding: 0 15px}
        .tabBar span.currentTab{background-color: #222;color: #fff}
        .tabCon {display: none}
    </style>
    <link href="__EXTEND__/ztree/styles/zTree/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <title>添加普通宝贝</title>
</head>
<body>
<div id="tab_demo" class="HuiTab">
    <div class="tabBar clearfix"><span>第一步：通用信息</span><span>第二步：属性设置</span></div>
    <form class="form form-horizontal" id="form-add-12"  method="post">

        <!--第一步：通用信息-->
        <div class="tabCon">
                <input type="hidden" name="tag" value="{{$tag}}">
                <input type="hidden" name="goods_id" id="goods_id" value="{{$goods_id}}">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>宝贝名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="请输入宝贝名称" id="goods_name" name="goods_name">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>限时最高价：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" onblur="checkNum(this,'限时最高价',1)" style="width:250px" placeholder="请输入限时最高价" id="highest_price" name="highest_price">
                    <span display="none" style="color:red"  class="show_info"></span>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>宝贝分类：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" id="cat_name" readonly="readonly" placeholder="清空则搜索全部宝贝" name="cat_name" nowvalue="{{$searchs['cat_name']}}" value="{{$searchs['cat_name']}}" class="input-text" style="width:250px" >
                    <input type="hidden" id="cat_id" name="cat_id" value="{{$searchs['cat_id']}}" >

                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>品牌：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <div class="select-box">
                        <select name="brand_id" class="select" id="brand_id">
                            <option value="">请选择品牌(请先选择宝贝分类)</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>是否上架：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal text-l">
                    <div class="radio-box">
                        <input name="is_up" type="radio" id="is_up-1" checked value="1">
                        <label for="is_up-1">上架</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="is_up-2" name="is_up"  value="2">
                        <label for="is_up-2">下架</label>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">热门推荐：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal text-l">
                    <div class="radio-box">
                        <input name="is_hot" type="radio" id="is_hot-1"   value="1">
                        <label for="is_hot-1">推荐</label>
                    </div>
                    <div class="radio-box">
                        <input name="is_hot" type="radio" id="is_hot-0" value="0"  checked >
                        <label for="is_hot-0">不推荐</label>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">排序：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="默认为0,数值越小越靠前" id="sort" name="sort">
                    <label  style="padding-left:0; color:#B3B3B3;">默认为0,数值越小排序越靠前</label>
                </div>
            </div>


            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2" style="text-align: center">
                    <button onClick="returnTwo();" class="btn btn-warning radius" type="button">&nbsp;&nbsp;下一步&nbsp;&nbsp;</button>
                </div>
            </div>
        </div>
        <!--第二步：属性设置-->
        <div class="tabCon">
            <div class="row cl" >
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>宝贝类型：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <div class="select-box">
                        <select name="type_id" class="select" onchange="getAttrList(0,this)">
                            <option value="">请选择宝贝类型</option>
                            <foreach name="typeList" item="type">
                                <option value="{{$type['id']}}" >{{$type['type_name']}}</option>
                            </foreach>
                        </select>
                    </div>
                </div>
            </div>
            <div id="attr_list">
            </div>

            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2" style="text-align: center">
                    <button onClick="returnOne();" class="btn btn-warning radius" type="button">&nbsp;&nbsp;上一步&nbsp;&nbsp;</button>
                    <input class="btn btn-warning radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" id="step3">
                </div>
            </div>
        </div>
    </form>

</div>


<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__EXTEND__/js/jquery-1.8.3.js"></script>

<script type="text/javascript" src="__EXTEND__/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__EXTEND__/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="__EXTEND__/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__EXTEND__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script src="__EXTEND__/style/js/exif.js?v=b26c6d5"></script>
<script src="__EXTEND__/style/js/lrz.js?v=c105d63"></script>
<!--upload-->

<script type="text/javascript" src="__EXTEND__/lib/webuploader/0.1.5/webuploader.min.js"></script>
<script>
    /*整数验证*/
    function checkNum(obj,desc,need=0){
        var check_val = $(obj).val();
        $(obj).parents(".formControls").find(".show_info").css("display","inline-block");
        if(check_val){
            if((/^[0-9]+?$/.test(check_val))){
                $(obj).parents(".formControls").find(".show_info").html("<i class=\"Hui-iconfont\">&#xe6a7;</i>"+desc+":符合条件");
                $(obj).parents(".formControls").find(".show_info").css("color","green");

            }else{
                $(obj).parents(".formControls").find(".show_info").html("<i class=\"Hui-iconfont\">&#xe6a6;</i>"+desc+":请输入整数");
                $(obj).parents(".formControls").find(".show_info").css("color","red");
            }
        }else{
            if(need == 1){
                $(obj).parents(".formControls").find(".show_info").html("必填");
            }else{
                $(obj).parents(".formControls").find(".show_info").html("");
            }
            $(obj).parents(".formControls").find(".show_info").css("color","red");
        }
    }
    /*整数或小数点后二位验证*/
    function checkNum2(obj,desc,need=0){
        var check_val = $(obj).val();
        $(obj).parents(".formControls").find(".show_info").css("display","inline-block");
        if(check_val){
            if((/^[0-9]+(.[0-9]{1,2})?$/.test(check_val))){
                $(obj).parents(".formControls").find(".show_info").html("<i class=\"Hui-iconfont\">&#xe6a7;</i>"+desc+":符合条件");
                $(obj).parents(".formControls").find(".show_info").css("color","green");

            }else{
                $(obj).parents(".formControls").find(".show_info").html("<i class=\"Hui-iconfont\">&#xe6a6;</i>"+desc+":请输入整数或小数二位");
                $(obj).parents(".formControls").find(".show_info").css("color","red");
            }
        }else{
            if(need == 1){
                $(obj).parents(".formControls").find(".show_info").html("必填");
            }else{
                $(obj).parents(".formControls").find(".show_info").html("");
            }
            $(obj).parents(".formControls").find(".show_info").css("color","red");
        }
    }
    /*根据分类id获取属性列表*/
    function getAttrList(goods_id,obj){
        var type_id = $(obj).val();
        if(type_id){
            $.ajax({
                type: 'POST',
                url: '{{:U("Admin/Attr/get_child_attr")}}',
                data: {
                    type_id: type_id,
                    goods_id:goods_id,
                },
                dataType: 'json',
                success: function(data){
                    if(data.status){
                        var html = '';
                        $(data.info).each(function(i, v){
                            html += '<div id="'+v.attr_id+'">';
                            html += '<div class="row cl" >\n' +
                                '                    <label class="form-label col-xs-2 col-sm-2">\n' +
                                '                        <a style="text-decoration:none;color:#438EB9" onClick="addAttr('+v.attr_id+',this)" href="javascript:;" title="添加属性值"><i class=\'Hui-iconfont\'>&#xe600;</i></a>\n' +
                                '                    </label>\n' +
                                '                    <div class="formControls col-xs-5 col-sm-9" style="background-color:#cccccc ">\n' +
                                '                        <span>'+v.attr_name+'：(';
                            if(v.attr_select_type == 2){
                                html += '多选';
                            }else{
                                html += '单选';
                            }
                            html += ')</span>\n' +
                                '                        <a style="text-decoration:none;color:#438EB9" onClick="removeDiv('+v.attr_id+')" href="javascript:;" title="移除属性">\n' +
                                '                            <i class=\'Hui-iconfont\'>&#xe64e;</i>\n' +
                                '                        </a>\n' +
                                '                    </div>\n' +
                                '                </div>';
                            $(v.attr).each(function(k, r){
                                html += ' <div class="row cl">\n' +
                                    '                    <label class="form-label col-xs-2 col-sm-2">\n' +
                                    '                        <input type="hidden" name="attr_id[]" value="'+v.attr_id+'">\n' +
                                    '                        <a style="text-decoration:none;color:#438EB9" onClick="removeAttr(this)" href="javascript:;" title="移除属性值"><i class=\'Hui-iconfont\'>&#xe6a1;</i></a>\n' +
                                    '                    </label>\n' +
                                    '                    <div class="formControls col-xs-5 col-sm-9">\n' +
                                    '                        <input type="text" class="input-text" style="width:40%;" value="'+r+'"   placeholder="请输入可选值"  name="attr_value[]">\n' +
                                    '                        损耗减价：\n' +
                                    '                        <input type="text" class="input-text" style="width:20%;" value="" onblur="checkNum2(this,\'\',)"  placeholder="请输入损耗减价"  name="attr_price[]">元\n' +
                                    '                        <span display="none" style="color:red"  class="show_info"></span>\n' +
                                    '                    </div>\n' +
                                    '                </div>';
                            });
                            html += '</div>';
                        });
                        $("#attr_list").html(html);

                    }else{
                        layer.msg(data.info,{icon:2,time:1000});
                    }
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        }else{
            $("#attr_list").html("");
        }
    }

    $(function() {

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });


        //提交
        $("#form-add-12").validate({
            rules: {
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{{:U('Admin/Goods/goodsAdd')}}",
                    success: function (data) {
                        if (data.status) {
                            layer.msg(data.info, {icon: 6, time: 1000});
                            setTimeout((function () {
                                $("form")[0].reset();
                                var tag = "{{$tag}}";
                                if (tag == 'child') {
                                    parent.window.location.href = "{{:U('Admin/Goods/goodsList')}}";
                                } else {
                                    window.location.href = "{{:U('Admin/Goods/goodsList')}}";
                                }
                            }), 1500);
                        } else {
                            layer.msg(data.info, {icon: 2, time: 1000});
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg('error!', {icon: 5, time: 1000});
                    }
                });
            }
        });
    });
    function addAttr(attr_id,obj){
        var divHtml = "<div class=\"row cl\">\n" +
            "                <label class=\"form-label col-xs-2 col-sm-2\">\n" +
            "                    <input type=\"hidden\" name=\"attr_id[]\" value=\""+attr_id+"\">"+
            "                    <a style=\"text-decoration:none;color:#438EB9\" onClick=\"removeAttr(this)\" href=\"javascript:;\" title=\"移除属性值\"><i class='Hui-iconfont'>&#xe6a1;</i></a>\n" +
            "                </label>\n" +
            "                <div class=\"formControls col-xs-5 col-sm-9\">\n" +
            "                    <input type=\"text\" class=\"input-text\" style=\"width:40%;\" value=\"\"   placeholder=\"请输入可选值\"  name=\"attr_value[]\">\n" +
            "                    损耗减价：\n" +
            "                    <input type=\"text\" class=\"input-text\" style=\"width:20%;\" value=\"\" onblur=\"checkNum2(this,'',1)\"  placeholder=\"请输入损耗减价\"  name=\"attr_price[]\">元\n" +
            "                    <span display=\"none\" style=\"color:red\"  class=\"show_info\"></span>\n" +
            "                </div>\n" +
            "            </div>";
        $("#"+attr_id).append(divHtml);
    }
    function removeAttr(obj){
        $(obj).parents(".row").remove();
    }
    function removeDiv(attr_id){
        $("#"+attr_id).remove();
    }
    function returnOne(){
        $.Huitab("#tab_demo .tabBar span","#tab_demo .tabCon","currentTab","click","0");
    }
    function returnTwo(){
        $.Huitab("#tab_demo .tabBar span","#tab_demo .tabCon","currentTab","click","1");
    }




</script>

<script type="text/javascript" src="__EXTEND__/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__EXTEND__/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__EXTEND__/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>


                <!--<script type="text/javascript" src="__EXTEND__/ztree/js/jquery-1.6.2.min.js" ></script>-->
                <!--<script type="text/javascript" src="__EXTEND__/ztree/js/browser.js" ></script>-->
                <script type="text/javascript" src="__EXTEND__/ztree/js/jquery.ztree.all-3.5.min.js" ></script>
                <script type="text/javascript" src="__EXTEND__/ztree/js/category_selecter.js" ></script>

                <script type="text/javascript">
                    $().ready(function(){
                        $.ajaxCategorySelecter("{{:U('Admin/Category/ajax_category')}}",$("#cat_name"), $("#cat_id"), "{{$goods_cat_id}}",'2');//2-不需要移动
                    });
                    /*存在品牌选项则对应动态生成品牌选择项*/
                    function changeBrandList(cat_id){
                        var target_obj = $("#brand_id");
                        if(target_obj.length>0 && cat_id != ''){
                            $.ajax({
                                type: 'POST',
                                url: '{{:U("Admin/Brand/getBrandByCat")}}',
                                data: {
                                    cat_id:cat_id,
                                },
                                dataType: 'json',
                                success: function(data){
                                    if(data.status){
                                        var brand_html = '<option value="">请选择品牌(请先选择宝贝分类)</option>';
                                        $(data.info).each(function(i, v){
                                            brand_html += '<option value="' + v.brand_id + '">' + v.title + '</option>';
                                        });
                                        target_obj.html(brand_html);
                                        return;
                                    }else{
                                        layer.msg(data.info,{icon:2,time:1000});
                                    }
                                },
                                error:function(data) {
                                    console.log(data.msg);
                                },
                            });
                        }
                    }
                </script>
<script>
    jQuery.Huitab =function(tabBar,tabCon,class_name,tabEvent,i){
        var $tab_menu=$(tabBar);
        // 初始化操作
        $tab_menu.removeClass(class_name);
        $(tabBar).eq(i).addClass(class_name);
        $(tabCon).hide();
        $(tabCon).eq(i).show();

        $tab_menu.bind(tabEvent,function(){

            if(this.innerText == ''){
                var add_goods_id = $("#add_goods_id").val();
                if(add_goods_id == ''){
                    layer.msg("", {icon: 2, time: 1000});
//                    return;
                }
            }
            $tab_menu.removeClass(class_name);
            $(this).addClass(class_name);
            var index=$tab_menu.index(this);
            $(tabCon).hide();
            $(tabCon).eq(index).show()})}
</script>
<script type="text/javascript">
    // #tab_demo 父级id
    // #tab_demo .tabBar span 控制条
    // #tab_demo .tabCon 内容区
    // click 事件 点击切换，可以换成mousemove 移动鼠标切换
    // 1	默认第2个tab为当前状态（从0开始）
    $(function(){

        $.Huitab("#tab_demo .tabBar span","#tab_demo .tabCon","currentTab","click","0");
    });




</script>


<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>